package cn.liumouren.jzxd.dao;

import cn.liumouren.jzxd.entity.Comment;
import cn.liumouren.jzxd.entity.User;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.apache.ibatis.annotations.*;

/**
 * @author Freeman Liu
 * @email llw599502537@gmail.com
 * @date 2020-10-30 16:28:20
 */
@Mapper
public interface CommentDao extends BaseMapper<Comment> {

    @Select("SELECT * FROM tb_comment WHERE zone_id = #{zoneId} ORDER BY add_time DESC")
    @Results(id = "commentMap", value = {
            @Result(property = "user",
                    javaType = User.class,
                    column = "user_id",
                    one = @One(select = "cn.liumouren.jzxd.dao.UserDao.getUserById")),
            @Result(property = "replyUser",
                    javaType = User.class,
                    column = "reply_user_id",
                    one = @One(select = "cn.liumouren.jzxd.dao.UserDao.getUserById"))
    })
    IPage<Comment> getPageCommentByZoneId(IPage<Comment> page, String zoneId);
}
